﻿using AnChao.WPF.Controls.Prism.Core;
using Prism.Commands;
using Prism.Mvvm;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AnChao.WPF.Controls.Prism.ViewModels
{
    public class MainWindowViewModel : BindableBase
    {
        private IApplicationCommands _applicationCommands;
        public IApplicationCommands ApplicationCommands
        {
            get
            {
                return _applicationCommands;
            }
            set
            {
                SetProperty(ref _applicationCommands, value);
            }

        }

        private bool _isCanExcute;
        public bool IsCanExcute
        {
            get
            {
                return _isCanExcute;
            }
            set
            {
                SetProperty(ref _isCanExcute, value);
            }
        }

        private string _currentTime;
        public string CurrentTime
        {
            get 
            {
                return _currentTime;
            }
            set
            {
                SetProperty(ref _currentTime, value);
            }
        }

        private string _title;
        public string Title
        {
            get 
            {
                return _title;
            }
            set
            {
                SetProperty(ref _title, value);
            }
        }

        public MainWindowViewModel(IApplicationCommands applicationCommands)
        {
            this.ApplicationCommands = applicationCommands;
            _applicationCommands.GetCurrentAllTimeCommand.RegisterCommand(GetYearCommand);

        }

        private DelegateCommand _getYearCommand;
        public DelegateCommand GetYearCommand =>
            _getYearCommand ?? (_getYearCommand = new DelegateCommand(ExcuteGetYearCommand).ObservesCanExecute(()=>IsCanExcute));


        void ExcuteGetYearCommand()
        {
            this.CurrentTime = DateTime.Now.ToString("yyyy");
        }
    }
}
